{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "#Written by Chia Chun Liang with aids of readatl06.py & merge.py (from captoolkit)\n",
    "#Read in ATL06 data, and split each .h5 file into 6 .h5 files based on beams and reformat each .h5 file's name\n",
    "#this .ipynb is put in the same directory with readatl06.py\n",
    "#first path is to specify where your input data is/are (pointed to file/files)\n",
    "#second path is to specify ouput directory (point to a directory)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "running in serial ...\n",
      "./ATL06_20181014001049_02350102_003_01_gt1l_spot6_A.h5\n",
      "./ATL06_20181014001049_02350102_003_01_gt1r_spot5_A.h5\n",
      "./ATL06_20181014001049_02350102_003_01_gt2l_spot4_A.h5\n",
      "./ATL06_20181014001049_02350102_003_01_gt2r_spot3_A.h5\n",
      "./ATL06_20181014001049_02350102_003_01_gt3l_spot2_A.h5\n",
      "./ATL06_20181014001049_02350102_003_01_gt3r_spot1_A.h5\n"
     ]
    }
   ],
   "source": [
    "#read in and reformating\n",
    "!python readatl06.py /home/jovyan/captoolkit/crossovers/contributors/chiachun/data/*.h5 -o ./"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Running sequential code ...\n",
      "Calculating lenght of output from all input files ...\n",
      "merge.py:66: H5pyDeprecationWarning: The default file mode will change to 'r' (read-only) in h5py 3.0. To suppress this warning, pass the mode you need to h5py.File(), or set the global default h5.get_config().default_file_mode, or set the environment variable H5PY_DEFAULT_READONLY=1. Available modes are: 'r', 'r+', 'w', 'w-'/'x', 'a'. See the docs for details.\n",
      "  with h5py.File(fn) as f:\n",
      "('reading', './ATL06_20181014001049_02350102_003_01_gt1l_spot6_A.h5')\n",
      "merge.py:113: H5pyDeprecationWarning: The default file mode will change to 'r' (read-only) in h5py 3.0. To suppress this warning, pass the mode you need to h5py.File(), or set the global default h5.get_config().default_file_mode, or set the environment variable H5PY_DEFAULT_READONLY=1. Available modes are: 'r', 'r+', 'w', 'w-'/'x', 'a'. See the docs for details.\n",
      "  with h5py.File(ifile) as f2:\n",
      "('reading', './ATL06_20181014001049_02350102_003_01_gt1r_spot5_A.h5')\n",
      "('reading', './ATL06_20181014001049_02350102_003_01_gt2l_spot4_A.h5')\n",
      "('reading', './ATL06_20181014001049_02350102_003_01_gt2r_spot3_A.h5')\n",
      "('reading', './ATL06_20181014001049_02350102_003_01_gt3l_spot2_A.h5')\n",
      "('reading', './ATL06_20181014001049_02350102_003_01_gt3r_spot1_A.h5')\n",
      "('merged', 6, 'files')\n",
      "('output ->', './proccessed_asending.h5')\n"
     ]
    }
   ],
   "source": [
    "#make only 2 output files, one is ascending, the other is descending\n",
    "!python merge.py ./*A.h5 -o ./processed_ascending.h5\n",
    "!python merge.py ./*D.h5 -o ./processed_descending.h5"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
